﻿$web = New-Object System.Net.WebClient

function Get-Chumby {
<#
 .Notes
 NAME: Get-Chumby
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Gets info about your Chumby

 .Description
 Returns a PowerShell object that contains info aobut your Chumby.  This includes the name, IP address, current channel, available channels, version, and PowerChumby version (version of the .cgi script).
 The object that is returned from this cmdlet can be piped into the other PowerChumby cmdlets to avoid having to type the IP address or name of the chumby.

 .Parameter Address
 The IP address or name of the chumby.  If you are using the name it must resolve to an IP address.

 .Inputs
 None

 .Outputs
 PSObject containg information about your Chumby.
 Verbose will give you the html page returned by the powerchumby.cgi script.

 .Example
 Get-Chumby 192.168.1.106

Name               : Jabberchumby
IP                 : 192.168.1.106
CurrentChannel     : Default
Channels           : {News, Morning, FunStuff, Default}
Version            : 3.7
PowerChumbyVersion : 1.0
 
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true,Position=0)]
        [string]$Address
    )
    $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=getchumby' -f $Address
    
    $chumby = New-Object psobject
    $page = $web.DownloadString($url)   
    Write-Verbose $page
    foreach ($line in ($page -split '\r\n')) {
        if ($line -match ':') {
            $vals = $line -split ':'
            $vals[1] = $vals[1] -replace '<BR>',''
            $vals[1] = $vals[1] -replace '\s+$', ''
            switch ($vals[0]) {
                "Name" {
                    $chumby |Add-Member NoteProperty -Name Name -Value $vals[1]
                }            
                "IP" {
                    $chumby |Add-Member NoteProperty -Name IP -Value $vals[1]
                }
                "CurrentChannel" {
                    $chumby |Add-Member NoteProperty -Name CurrentChannel -Value $vals[1]
                }
                "Channels" {
                    $chumby |Add-Member NoteProperty -Name Channels -Value ($vals[1] -split ',')
                }
                "Version" {
                    $chumby |Add-Member NoteProperty -Name Version -Value $vals[1]
                }
                "PowerChumbyVersion" {
                    $chumby |Add-Member NoteProperty -Name PowerChumbyVersion -Value $vals[1]
                }
            }
        }
    }
    $chumby
}

function Set-ChumbyMute {
<#
 .Notes
 NAME: Set-ChumbyMute
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Turns the mute on or off

 .Description
 Turns mute on or off.  Default is to turn it on. 

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object.

 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 None.  There is no indication whether the Mute was successful.  
 Verbose will give you the html page returned by the powerchumby.cgi script.

 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-ChumbyMute
 
 .Example
 Set-ChumbyMute -IP 192.168.1.106 -Off
 
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP,
        [Parameter(Mandatory=$false)]
        [switch] $Off
    )
    if ($Off) {
        $mute = "off"
    }
    else {
        $mute = "on"
    }
    $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=mute&var1={1}' -f $IP, $mute
    $page = $web.DownloadString($url)   
    Write-Verbose $page
}

function Set-ChumbyVolume {
<#
 .Notes
 NAME: Set-ChumbyVolume
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Sets your chumby's volume to a new level

 .Description
 Sets your chumby's volume to a new level.  This can be a percentage of the maximum volume ranging from 0-100 percent.

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object.
 
 .Parameter Level
 This is the percentage of the maximum volume that you would like to set the volume to.
 This number can be 0 - 100.

 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 None.  There is no indication whether the SetVolume was successful.
 Verbose will give you the html page returned by the powerchumby.cgi script.

 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-ChumbyVolume 50
 
 Description
 -----------
 Set the volume to 50% of the maximum volume level
  
 .Example

 Set-ChumbyVolume -IP 192.168.1.106 -Level 100
 
 Description
 -----------
 Set the volume to the maximum volume level
   
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP,
        [Parameter(Mandatory=$true, Position = 0)]
        [int]
        [ValidateRange(0,100)]
        $Level
    )
    $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=setvolume&var1={1}' -f $IP, $Level
    $page = $web.DownloadString($url)   
    Write-Verbose $page
}

function Start-ChumbyMusic {
<#
 .Notes
 NAME: Start-ChumbyMusic
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.1
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release
 12/6/2010 1.1
 Added support for pls files

 .Synopsis
 Starts a new stream in the music player of your Chumby.

 .Description
 Starts a new stream in the music player of your Chumby.  You can pass a url (including file:// urls that hit an mp3) to your chumby.  It accepts the standard stream types that the chumby accepts in the "My Streams" section of the Music player.

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object.
 
 .Parameter Url
 This is a url to the stream you would like to start playing in your Chumby.
 
 .Parameter Pls
 This is an optional switch parameter that specifies that the url is a pls file.  The cmdlet will download and inspect the pls file.  It will then pass the first file located in File#= to the chumby. 

 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 None.  There is no indication whether the Start-ChumbyMusic was successful.
 Verbose will give you the html page returned by the powerchumby.cgi script.

 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Start-ChumbyMusic http://media.libsyn.com/media/powerscripting/PSPodcast-089.mp3

 Description
 -----------
 Start playing the PowerShell 2.0 Release Party episode of the PowerScripting Podcast
  
 .Example
 Start-ChumbyMusic -IP 192.168.1.106 "file://mnt/usb/01 John The Fisherman.mp3"

 Description
 -----------
 Start playing an mp3 located on the usb:
 
 .Example
 Get-Chumby 192.168.1.106 |Start-ChumbyMusic http://www.dubstep.fm/listen.pls -Pls
 
 Description
 -----------
 Start playing a pls stream
 
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP,
        [Parameter(Mandatory=$true, Position = 0)]
        [string]
        $Url,
        [Parameter(Mandatory=$false)]
        [switch]
        $Pls
    )
    if ($Pls) {
        if ($web.DownloadString($url) -match '(?m)file\d*\s*=\s*([\S]*)\s*') {
            $url = $matches[1]
        }
    }
    $u2 = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=playmusic&var1={1}' -f $IP, $url
    $page = $web.DownloadString($u2)   
    Write-Verbose $page
}

function Stop-ChumbyMusic {
<#
 .Notes
 NAME: Stop-ChumbyMusic
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Stops the music player on your Chumby.

 .Description
 Stops the music player on your Chumby.  There is currently no pause or way to start playing what you had open again.  You can use Start-ChumbyMusic to start a new stream on the music player.

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object. 

 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 None.  There is no indication whether the Stop-ChumbyMusic was successful.
 Verbose will give you the html page returned by the powerchumby.cgi script.

 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Stop-ChumbyMusic
 
 .Example
 Stop-ChumbyMusic -IP 192.168.1.106
 
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP
    )
    $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=stopmusic' -f $IP
    $page = $web.DownloadString($url)   
    Write-Verbose $page
}

function Set-ChumbyNightMode {
<#
 .Notes
 NAME: Set-ChumbyNightMode
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Turns night mode on or off

 .Description
 Turns night mode on or off.  Default is to turn it on. 

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object.

 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 None.  There is no indication whether night mode was successful.  
 Verbose will give you the html page returned by the powerchumby.cgi script.

 .Example 
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-NightMode

 Description
 -----------
 Turn Night Mode on
  
 .Example 
 Set-NightMode -IP 192.168.1.106 -Off
 
 Description
 -----------
 Turn Night Mode on 
 
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP,
        [Parameter(Mandatory=$false)]
        [switch] $Off
    )
    if ($Off) {
        $mute = "off"
    }
    else {
        $mute = "on"
    }
    $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=nightmode&var1={1}' -f $IP, $mute
    $page = $web.DownloadString($url)   
    Write-Verbose $page
}

function Set-ChumbyChannel {
<#
 .Notes
 NAME: Set-ChumbyChannel
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Changes the channel of your chumby.

 .Description
 Changes the channel of your chumby.  To see a list of valid channels you can inspect the channels property of Get-Chumby, i.e., Get-Chumby 192.168.1.106 |select Channels

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object.
 
 .Parameter Name
 This is the name of the channel you would like to change to.  This parameter is case sensitive.  If you use an invalid channel name nothing will happen.

 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 None.  There is no indication whether the Set-ChumbyChannel was successful.
 Verbose will give you the html page returned by the powerchumby.cgi script.

 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-ChumbyChannel default
 
 Description
 -----------
 Sets the chumby to use the default channel
 
 
 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-ChumbyChannel -Name $chumby.Channels[3]

 Description
 ----------- 
 Sets the chumby to use the 4th channel in the list of channels available
 
 .Example
 Set-ChumbyChannel -IP 192.168.1.106 "FunStuff"

 Description
 ----------- 
 Sets the chumby to use a channel called FunStuff
 
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP,
        [Parameter(Mandatory=$true, Position = 0)]
        [string]
        $Name
    )
    $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=setchannel&var1={1}' -f $IP, $Name
    $page = $web.DownloadString($url)   
    Write-Verbose $page
}

function Reset-ChumbyChannel {
<#
 .Notes
 NAME: Reset-ChumbyChannel
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Reloads the current channel on your chumby with its settings from Chumby.com.

 .Description
 Reloads the current channel.  This is useful if you are making changes to the channel via chumby.com and want to see the changes immediately.

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object.
 
 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 None.  There is no indication whether the Reset-ChumbyChannel was successful.
 Verbose will give you the html page returned by the powerchumby.cgi script.

 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Reset-ChumbyChannel
 
 .Example
 Reset-ChumbyChannel -IP 192.168.1.106
 
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP
    )
    $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=reloadchannel' -f $IP
    $page = $web.DownloadString($url)   
    Write-Verbose $page
}

function Set-ChumbyWidget {
<#
 .Notes
 NAME: Set-ChumbyWidget
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Changes the currently running widget of your chumby or sets the widgets to shuffle.

 .Description
 This cmdlet can do one of the following:
    * Set a widget to a specific widget
    * Go to the next widget in the channel
    * Go to the previous widget in the channel
    * Shuffle the widgets in the channel
  Only one of these functions can be performed at a time.  You will get an error if you try to do more than one.

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object.
 
 .Parameter Name
 This is the name of the channel you would like to change to.  This parameter is case sensitive.  If you use an invalid channel name nothing will happen.
 
 .Parameter Next
 This switch signifies that the chumby should skip to the next widget in the channel.
 
 .Parameter Prev
 This switch signifies that the chumby should go to the previous widget in the channel.
 
 .Parameter Shuffle
 This will shuffle the widgets in the current channel.  Unfortunately, there is no way to turn off shuffle at the moment.
 
 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 None.  There is no indication whether the Set-ChumbyWidget was successful.
 Verbose will give you the html page returned by the powerchumby.cgi script.

 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-ChumbyWidget Twitter
 
 Description
 -----------
 Sets the widget of the Chumby to the Twitter widget
 
 .Example 
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-ChumbyWidget -Name "BigBen 2.0"
 
 Description
 -----------
 Sets the widget of the Chumby to the Big Ben 2.0 widget
 
 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-ChumbyWidget -Next

 Description
 -----------
 Sets the chumby to use the next widget in the current channel
   
 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-ChumbyWidget -Prev
 
 Description
 ----------- 
 Sets the chumby to use the previous widget in the current channel
 
 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-ChumbyWidget -Shuffle

 Description
 -----------
 Shuffles the current channel's widgets
   
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP,
        [Parameter(Mandatory=$false, Position = 0, ParameterSetName="SetWidget")]
        [string]
        $Name,
        [Parameter(Mandatory=$false, ParameterSetName="NextWidget")]
        [switch]$Next,
        [Parameter(Mandatory=$false, ParameterSetName="PrevWidget")]
        [switch]$Prev,
        [Parameter(Mandatory=$false, ParameterSetName="ShuffleWidget")]
        [switch]$Shuffle
    )
    $url = ""    
    switch ($PsCmdlet.ParameterSetName) {
        "SetWidget" {
            $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=setwidget&var1={1}' -f $IP, $name
        }
        "NextWidget" {
            $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=nextwidget' -f $IP
        }
        "PrevWidget" {
            $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=prevwidget' -f $IP
        }
        "ShuffleWidget" {
            $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=shufflewidget' -f $IP
        }
    }
    $page = $web.DownloadString($url)   
    Write-Verbose $page
}

function Set-ChumbyScreen {
<#
 .Notes
 NAME: Set-ChumbyScreen
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Controls the brightness of a chumby's screen

 .Description
 Controls the brightness of a chumby's screen.  This can be set to bright, dim, or off

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object.
 
 .Parameter Mode
 This parameter accepts one of the three accepted modes for the chumby's screen:
    * Bright - This is the default mode for a chumby's screen
    * Dim - This will dim the chumby's screen
    * Off - This will shut off the chumby's screen

 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 None.  There is no indication whether the Set-ChumbyScreen was successful.
 Verbose will give you the html page returned by the powerchumby.cgi script.

 .Example
 This will turn your chumby's screen off
 
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Set-ChumbyScreen off
 
 .Example
 Set-ChumbyScreen -IP 192.168.1.106 bright
 
 Description
 -----------
 This will set your chumby's screen to the default bright mode

 .Example
 Get-Chumby 192.168.1.106 |Set-ChumbyScreen -mode dim
 
 Description
 -----------
 This will dim your chumby's screen
  
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP,
        [Parameter(Mandatory=$true, Position = 0)]
        [string]
        [ValidateSet(“off”, “dim", “bright”)]
        $mode
    )
    $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=setscreen&var1={1}' -f $IP, $mode
    $page = $web.DownloadString($url)   
    Write-Verbose $page
}

function Enable-ChumbySSH {
<#
 .Notes
 NAME: Enable-ChumbySSH
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Enable sshd on the chumby

 .Description
 Enable sshd on the chumby.  It should be noted that the default password for root is blank on a chumby so this should be used with extreme caution.
 SSH will not persist between reboots.

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object.

 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 The string returned via the start command will be returned.

 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Enable-ChumbySSH
 
 .Example
 Enable-ChumbySSH -IP 192.168.1.106
 
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP
    )
    $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=sshd&var1=on' -f $IP
    $page = $web.DownloadString($url)   
    if ($page -match '<BR>([\s\S]+)</body>') {
        $matches[1] -replace '<BR>',''
    }  
    else {
        $page
    }
}

function Disable-ChumbySSH {
<#
 .Notes
 NAME: Disable-ChumbySSH
 AUTHOR: Tome Tanasovski
 Author's website: http://powertoe.wordpress.com
 Author's twitter: http://twitter.com/toenuff
 Version: 1.0
 CREATED: 12/5/2010
 LASTEDIT:
 12/5/2010 1.0
 Initial Release

 .Synopsis
 Disable sshd on the chumby

 .Description
 Disable sshd on the chumby.  This does not change whether sshd starts up automatically on your chumby the next time it reboots.  By default sshd is disabled on a chumby during a reboot, but it can be configured otherwise.
 Also, this will not affect any existing SSH sessions.  Those will continue to run, but no future connections will be possible.

 .Parameter IP
 This is the IP address or name of your chumby.  If you are using the name it must resolve to an IP address.  
 If you pipe a chumby object that is returned from Get-Chumby, this parameter is passed from the chumby object.

 .Inputs
 Can take an optional Chumby object returned from Get-Chumby rather than specifying a value for the IP parameter.

 .Outputs
 The string returned via the stop command will be returned.

 .Example
 $chumby = Get-Chumby 192.168.1.106
 $chumby |Disable-ChumbySSH
 
 .Example
 Disable-ChumbySSH -IP 192.168.1.106
 
 .LINK
 http://powerchumby.codeplex.com

#>
    param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
        [string]
        [ValidatePattern('^[\w.]+$')]
        $IP
    )
    $url = 'http://{0}/cgi-bin/custom/powerchumby.cgi?action=sshd&var1=off' -f $IP
    $page = $web.DownloadString($url) 
    if ($page -match '<BR>([\s\S]+)</body>') {
        $matches[1] -replace '<BR>',''
    }  
    else {
        $page
    }
}
